/**
 * Created by CSJ11 on 2017/7/3.
 */
'use strict';
angular.module('app')
    .controller('headlinesController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
          // alert(  $("#account").html());
            $scope.title = '头条内容';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/notice/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }
             $scope.quer = function () {
              $scope.searchParams.startTime=$("#startTime").val();
              $scope.searchParams.endTime=$("#endTime").val();
              $scope.searchParams.startTimeOne=$("#startTimeOne").val();
              $scope.searchParams.endTimeOne=$("#endTimeOne").val();

                if($('#startTime').val() && $('#endTime').val()){
                    if($('#startTime').val() > $('#endTime').val()){
                      $scope.alertModal({'content':'有效期开始时间不能大于结束时间'});
                      return;
                    }
                }
                 if($('#startTimeOne').val() && $('#endTimeOne').val()){
                    if($('#startTimeOne').val() > $('#endTimeOne').val()){
                      $scope.alertModal({'content':'创建时间开始时间不能大于结束时间'});
                      return;
                    }
                }
                if(!$('#startTimeOne').val() && $('#endTimeOne').val()){
                      $scope.alertModal({'content':'请选择创建时间的开始时间'});
                      return;
                }
                if(!$('#startTime').val() && $('#endTime').val()){
                  $scope.alertModal({'content':'请选择有效期的开始时间'});
                  return;
                }
                if($('#startTime').val() && !$('#endTime').val()){
                  $scope.alertModal({'content':'请选择有效期的结束时间'});
                  return;
                }

                 $scope.search();
            }

            $scope.searchRe = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/notice/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                        $(".editSortBtn").show();
                        $(".saveSortBtn").hide();
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.selected = [];
            $scope.search();
            $scope.clearSearch = function() {

                $scope.searchParams= { };
                $scope.search();
                $(".editSortBtn").show();
                $(".saveSortBtn").hide();
            }
            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };

            // 删除轮播图
            $scope.deleteById=function (noticeNo) {
                $scope.alertModel({
                    text:'确定删除？',
                    btnCancel:true,
                    resCode:"10000"
                }).then(function(){
                    $.ajax({
                        url : $scope.app.project_name+'/notice/delete',
                        data: {noticeNo:noticeNo}
                    }).then(function(result) {
                        $scope.loading = false;
                        $scope.alertModal({"content":"操作成功"});
                        if (result.httpCode != 200) {
                            $scope.alertModal(result.msg);
                        }
                        $scope.search();
                    });

                })

            }
             // 平台名称鼠标移入的动作
            $scope.introduction = [];
            $scope.preview = function(introduction){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.left = event.clientX;
                showDiv.style.top = event.clientY;
                showDiv.style.display = 'block';
                showDiv.innerHTML = introduction;
            }
            // 平台名称鼠标移出的动作
            $scope.outHide = function(){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.display = 'none';
                showDiv.innerHTML = '';
            }
        } ]);